
class Location:
    def __init__(self, result: str):
        self.result = result
        self.continent = None  # 洲
        self.country = None  # 国家/地区
        self.province = None  # 省份
        self.city = None  # 城市
        self.district = None  # 区县
        self.isp = None  # 运营商
        self.area_code = None  # 区域代码
        self.country_english = None  # 国家/地区英文
        self.country_code = None  # 国家/地区英文简写
        self.longitude = None  # 经度
        self.latitude = None  # 纬度
        self.elevation = None  # 海拔
        self.zip_code = None  # 邮编
        self.city_code = None  # 城市代码
        self.weather_station = None  # 气象站
        self.asn = None  # AS码
        self.preserve = None  # 预留
        self.street = None  # 街道
        self.time_zone = None  # 时区
        self.parse_location()

    def parse_location(self):
        infos = self.result.split("|")
        if len(infos) != 19:
            raise ValueError("查询结果格式错误或离线库非归属地库")

        self.continent = infos[0]  # 洲
        self.country = infos[1]  # 国家/地区
        self.province = infos[2]  # 省份
        self.city = infos[3]  # 城市
        self.district = infos[4]  # 区县
        self.isp = infos[5]  # 运营商
        self.area_code = infos[6]  # 区域代码
        self.country_english = infos[7]  # 国家/地区英文
        self.country_code = infos[8]  # 国家/地区英文简写
        self.longitude = infos[9]  # 经度
        self.latitude = infos[10]  # 纬度
        self.elevation = infos[11]  # 海拔
        self.zip_code = infos[12]  # 邮编
        self.city_code = infos[13]  # 城市代码
        self.weather_station = infos[14]  # 气象站
        self.asn = infos[15]  # AS码
        self.preserve = infos[16]  # 预留
        self.street = infos[17]  # 街道
        self.time_zone = infos[18]  # 时区


class Scenes:
    def __init__(self, result: str):
        self.result = result
        self.scenes = None  # 场景
        self.isp = None  # 运营商
        self.as_num = None  # AS码
        self.parse_scenes()

    def parse_scenes(self):
        infos = self.result.split("|")
        if len(infos) != 1:
            raise ValueError("查询结果格式错误或离线库非场景库")
        scenes_cn = ""
        if infos[0] == "EDU":
            scenes_cn = "教育机构"
        elif infos[0] == "GTW":
            scenes_cn = "企业专线"
        elif infos[0] == "GOV":
            scenes_cn = "政府机构"
        elif infos[0] == "NET":
            scenes_cn = "基础设施"
        elif infos[0] == "ORG":
            scenes_cn = "组织机构"
        elif infos[0] == "DYN":
            scenes_cn = "家庭宽带"
        elif infos[0] == "IDC":
            scenes_cn = "数据中心"
        elif infos[0] == "MOB":
            scenes_cn = "移动网络"
        elif infos[0] == "CDN":
            scenes_cn = "内容分发"
        elif infos[0] == "DNS":
            scenes_cn = "域名解析"
        elif infos[0] == "BOGON":
            scenes_cn = "保留"
        else:
            scenes_cn = "-"
        self.scenes = scenes_cn  # 场景




class Proxy:
    def __init__(self, result: str):
        self._result = result
        self._proxy_type = ""
        self._proxy_time = ""
        self._parse_proxy()

    def _parse_proxy(self):
        infos = self._result.split('|')
        if len(infos) != 3:
            print("查询结果格式错误或离线库非代理v2库")
            return
        if infos[0] == "否":
            self._proxy_type = "不是代理"
        else:
            proxy_types= infos[1].split(",")
            p = []
            for i in proxy_types:
                if i:
                    p.append(i)

            self._proxy_type = "|".join(p)
            self._proxy_time = infos[2]

    def get_proxy_type(self) -> str:
        return self._proxy_type
